/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package restaurante;

import javafx.event.EventHandler;
import javafx.scene.Cursor;
import javafx.scene.Group;
import javafx.scene.effect.BlendMode;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.shape.Shape;

/**
 *
 * @author 66785403
 */
public class Salon extends Pane {

    private ScrollButtons scrollButtons;
    private Group group;
    private Restaurante rest;
    public boolean shapePressed = false;
    private Area mesaSeleccionada;
    public double xScene, yScene, xDrag, yDrag;

    public Salon(double width, double height, ScrollButtons scrollButtons_, Restaurante rest_) {
        this.scrollButtons = scrollButtons_;
        this.rest = rest_;
        scrollButtons.setVisible(false);
        group = new Group();
        //this.getChildren().addAll(group);
        this.setPrefSize(1000, 1000);
        this.setMinSize(1000, 1000);
        this.setOnMousePressed(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent t) {
//                xDrag = t.getX() - mesaSeleccionada.getWidth();
//                yDrag = t.getY() - mesaSeleccionada.getHeight();
            }
        });

        this.setOnMouseDragged(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent t) {
                if (shapePressed) {
                    xScene = t.getX();
                    yScene = t.getY();
                    mesaSeleccionada.moveObject(xScene, yScene);
                    t.consume();
                }
            }
        });
    }

    public void addShape(final Area mesa, double x, double y) {

        mesa.setOnMousePressed(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent t) {
                shapePressed = true;
                setCursor(Cursor.CROSSHAIR);
                mesaSeleccionada = mesa;
                t.consume();
            }
        });

        mesa.setOnMouseReleased(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent t) {
                shapePressed = false;
                setCursor(Cursor.DEFAULT);
                rest.sp.setPannable(true);
                t.consume();
            }
        });
        this.getChildren().add(mesa);
        mesa.setLayoutX(x);
        mesa.setLayoutY(y);
        double newX = x + 150;
        double newY = y + 150;
        double oldX = getMinWidth();
        double oldY = getMinHeight();
        setMinHeight((oldY < newY) ? newY : oldY);
        setMinWidth((oldX < newX) ? newX : oldX);

    }

    public void toggleScrollButtons(boolean visible) {
        scrollButtons.setVisible(visible);
    }
}
